
****************************************************************************
**Win or Lose: Residential Sorting After a School Choice Lottery
*By Andrew Bibler & Stephen B Billings

****************************************************************************

use all-lottery-movers-analysis.dta , clear 

keep if (year>2008 & ksample & stayer==1)

gen attappch1schl = (curr_lead1==appch1school)
gen attassschl = (curr_lead1==assschl)
gen notmove1 = (1 - move1)
gen move1_won = wonfirst*move1
gen notmove1_won = wonfirst*notmove1
gen move1_lost = (1 - wonfirst)*move1
gen notmove1_lost = notmove1*(1 - wonfirst)
	
lab var move1 "Mover (Change HS + Exit)"
lab var changehs "Change HS (Stay)"
lab var atthome1 "Attend Lagged HS"
lab var attappch1schl "Attend First Choice School"
lab var attassschl "Attend Assigned School"
lab var female "Female"
lab var lunch "Ec. Disadvantage"
lab var wonany "Won Any Choice"
lab var app2 "Made Second Choice"
lab var app3 "Made Third Choice"

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch if wonfirst==1
estadd scalar N_ind = e(N)
est store A

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch if notmove1_won==1
estadd scalar N_ind = e(N)
est store B

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch if move1_won==1
estadd scalar N_ind = e(N)
est store C

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch if wonfirst==0
estadd scalar N_ind = e(N)
est store D

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch if notmove1_lost==1
estadd scalar N_ind = e(N)
est store E

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch if move1_lost==1
estadd scalar N_ind = e(N)
est store F

** Table A3
esttab A B C D E F using tableA3.tex , replace ///
mtitles("Full Sample" "Same HS" "Change HS" "Full Sample" "Same HS" "Change HS") ///
refcat(move1 "\textit{Outcomes}" app2 "\textit{Student Attributes}" , nolabel) ///
cells(mean(fmt(2)) sd(fmt(2)par)) label booktabs nonum collabels(none) gaps f ///
stats(N_ind , fmt(%1s %9.0f) layout("\multicolumn{1}{c}{@}") labels(`"Observations"')) 
	
	
use all-lottery-movers-analysis.dta , clear

keep if (year>2008 & sixsample & stayer==1)

gen attappch1schl = (curr_lead1==appch1school)
gen attassschl = (curr_lead1==assschl)
gen notmove1 = (1 - move1)
gen move1_won = wonfirst*move1
gen notmove1_won = wonfirst*notmove1
gen move1_lost = (1 - wonfirst)*move1
gen notmove1_lost = notmove1*(1 - wonfirst)

lab var move1 "Mover (Change HS + Exit)"
lab var changehs "Change HS (Stay)"
lab var atthome1 "Attend Lagged HS"
lab var attappch1schl "Attend First Choice School"
lab var attassschl "Attend Assigned School"
lab var female "Female"
lab var lunch "Ec. Disadvantage"
lab var wonany "Won Any Choice"
lab var app2 "Made Second Choice"
lab var app3 "Made Third Choice"

lab var math_lag "Math Lag 1"
lab var read_lag "Read Lag 1"
lab var lep_Y_lag "LEP Lag 1"
	
estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch math_lag read_lag lep_Y_lag if wonfirst==1
estadd scalar N_ind = e(N)
est store A

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch math_lag read_lag lep_Y_lag if notmove1_won==1
estadd scalar N_ind = e(N)
est store B

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch math_lag read_lag lep_Y_lag if move1_won==1
estadd scalar N_ind = e(N)
est store C

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch math_lag read_lag lep_Y_lag if wonfirst==0
estadd scalar N_ind = e(N)
est store D

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch math_lag read_lag lep_Y_lag if notmove1_lost==1
estadd scalar N_ind = e(N)
est store E

estpost sum move1 changehs atthome1 attappch1schl attassschl wonany app2 app3 female black white hispanic lunch math_lag read_lag lep_Y_lag if move1_lost==1
estadd scalar N_ind = e(N)
est store F
		
** Table A4
esttab A B C D E F using tableA4.tex , replace ///
mtitles("Full Sample" "Same HS" "Change HS" "Full Sample" "Same HS" "Change HS") ///
refcat(move1 "\textit{Outcomes}" app2 "\textit{Student Attributes}" , nolabel) ///
cells(mean(fmt(2)) sd(fmt(2)par)) label booktabs nonum collabels(none) gaps f ///
stats(N_ind , fmt(%1s %9.0f) layout("\multicolumn{1}{c}{@}") labels(`"Observations"')) 


	
	
	
	
	
	
	
	
	
	
	
	
	
